/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>Project: jse2303 - List3
 * <p>Powered by webrx On 2023-07-19 10:52:49
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class List3 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        //添加元素
        list.add(10);
        list.add(20);
        list.add(0, 1);
        list.addAll(List.of(3, 2, 1, 3, 20));
        System.out.println(list);

        //修改元素
        list.set(0, 100);

        list.addAll(0, List.of(11, 22, 33));


        //判断元素
        System.out.println(list.contains(10));
        System.out.println(list.contains(100));
        System.out.println(list.indexOf(100));
        System.out.println(list.indexOf(10));
        System.out.println(list.containsAll(List.of(3, 2, 5)));

        //删除元素
        //Integer i = 20;
        //list.remove(i);
        //list.clear();
        //System.out.println(list.size());

        //批量删除多个元素
        //list.removeAll(List.of(20, 3));
        //list.removeIf(e -> e == 20);
        //list.removeIf(e -> e % 2 == 0);

        //Collections 是个工具类
        Collections.reverse(list); //位置倒序
        //System.out.println(list);

        for (int i : list) {
            System.out.println(i);
        }
    }
}
